﻿/*
	Wind.cs
	Copyright (C) 2012 Keagan Ladds

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Text;

namespace WeatherPlugin
{
    public class Wind
    {
        public enum WindDirection
        {
            North, East, West, South, North_West, North_East, South_East, South_West
        };

        public WindDirection Direction;
        public float Speed;

        public void Parse(string Data)
        {
            int iPos = Data.IndexOf("at");
            string sDirection = Data.Substring(6, iPos - 7);
            Data = Data.Remove(0, iPos + 3);
            iPos = Data.IndexOf("mph");
            string sSpeed = Data.Substring(0, iPos - 1);
            Speed = (float)Math.Round(int.Parse(sSpeed) * 1.609344f, 2);
            switch (sDirection)
            {
                case "N":
                    Direction = WindDirection.North;
                    break;

                case "E":
                    Direction = WindDirection.East;
                    break;

                case "S":
                    Direction = WindDirection.South;
                    break;

                case "W":
                    Direction = WindDirection.West;
                    break;

                case "NE":
                    Direction = WindDirection.North_East;
                    break;

                case "NW":
                    Direction = WindDirection.North_West;
                    break;

                case "SE":
                    Direction = WindDirection.South_East;
                    break;

                case "SW":
                    Direction = WindDirection.South_West;
                    break;
            }
        }

        public string DirectionAsString()
        {
            switch (Direction)
            {
                case WindDirection.North:
                    return "North";
                    break;

                case WindDirection.East:
                    return "East";
                    break;

                case WindDirection.South:
                    return "South";
                    break;

                case WindDirection.West:
                    return "West";
                    break;

                case WindDirection.North_East:
                    return "North East";
                    break;

                case WindDirection.North_West:
                    return "North West";
                    break;

                case WindDirection.South_East:
                    return "South East";
                    break;

                case WindDirection.South_West:
                    return "South West";
                    break;
            }

            return "";
        }

        public override string ToString()
        {
            return DirectionAsString() + " at " + Speed.ToString() + "km/h";
        }
    }
}
